package com.banfan.almond.web.controller;

import com.banfan.almond.base.validator.group.Insert;
import com.banfan.almond.entity.vo.AdminVO;
import com.banfan.almond.utils.ResultUtil;
import com.banfan.almond.web.annotation.OperationLogger.OperationLogger;
import com.banfan.almond.web.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/auth")
@Slf4j
public class LoginController {


    @Autowired
    private AdminService adminService;


    @OperationLogger(operation = "登陆")
    @PostMapping("/login")
    public String login(@Validated({Insert.class}) @RequestBody AdminVO adminVO, BindingResult result) {
        // 参数校验
//        ThrowableUtils.checkParamArgument(result);
        return adminService.login(adminVO);
    }

    @OperationLogger(operation = "注册")
    @PostMapping("/register")
    public String register(@Validated({Insert.class}) @RequestBody AdminVO adminVO, BindingResult result) {
//        ThrowableUtils.checkParamArgument(result);
        return adminService.register(adminVO);
    }

    @OperationLogger(operation = "登出")
    @PostMapping("/logout")
    public String logout(@Validated({Insert.class}) @RequestBody AdminVO adminVO, BindingResult result) {
//        ThrowableUtils.checkParamArgument(result);
        return adminService.logout(adminVO);
    }

    @GetMapping("/login")
    public String get() {
        System.out.println("/login/get");
        // 参数校验
//        ThrowableUtils.checkParamArgument(result);
        return ResultUtil.successWithData("/login/get");
    }


}
